﻿using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfance;
using B.S.BasicData.Read.Apilication.Common.Menu;
using MediatR;

namespace B.S.BasicData.Read.Apilication.Handler.Menu
{
    public class GetOneCommandHandle:IRequestHandler<GetOneCommand,ApiResult<List<MenuModel>>>
    {
        private readonly IBaseRepository<MenuModel> MenuDal;

        public GetOneCommandHandle(IBaseRepository<MenuModel> menuDal)
        {
            MenuDal = menuDal;
        }

        public Task<ApiResult<List<MenuModel>>> Handle(GetOneCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<MenuModel>> res = new ApiResult<List<MenuModel>>();

            var info = MenuDal.GetAll().Where(x => x.ParentId == request.MeenuId);

            if (info.Count() > 0)
            {
                res.Code = ApiEnum.Success;
                res.Message = "有子集";
                return Task.FromResult(res);
            }
            else
            {
                res.Code = ApiEnum.Error;
                res.Message = "没有子集";
                return Task.FromResult(res);
            }
        }
    }
}
